import { defineStore } from 'pinia';
import { Request } from '@/app/request.js';
import type { SelectOption, CascaderOption } from '@/common/types/app.js';
import { reactive, ref } from 'vue';

export const useAppStore = defineStore('selectOption', () => {
    
    const SelectOptionCarry = reactive<SelectOption[]>([
        { value: 'A', label: '进场' },
        { value: 'T', label: '出场' },
        { value: 'S', label: '起租' },
        { value: 'E', label: '退租' },
    ]);
    const SelectOptionEF = reactive<SelectOption[]>([
        { value: 'E', label: '空箱' },
        { value: 'F', label: '重箱' },
    ]);
    const SelectOptionTrade = reactive<SelectOption[]>([
        { value: '1', label: '外贸' },
        { value: '2', label: '内贸' },
    ]);
    const SelectOptionYN = reactive<SelectOption[]>([
        { value: 'Y', label: '是' },
        { value: 'N', label: '否' },
    ]);
    const SelectOptionReply = reactive<SelectOption[]>([
        { value: 'S', label: '提交'},
        { value: 'R', label: '批复'},
        { value: 'E', label: '退回'},
    ]);
    const SelectOptionCntrOwnerReply = reactive<SelectOption[]>([
        
        { value: 'R', label: '批复'},
        { value: 'E', label: '退回'},
    ]);
    // 进场计划类型
    /* const SelectOptionPlanKind = reactive<SelectOption[]>([
        { value: '0', label: '堆存箱' },
        { value: '2', label: '出售箱' },
    ]); */
    // 费用收付
    const SelectOptionFeeInOut = reactive<SelectOption[]>([
        { value: 'I', label: '收款' },
        { value: 'O', label: '付款' },
    ]);
    const cntrSiz = ref<SelectOption[]>([]); // 尺寸
    const cntrTyp = ref<SelectOption[]>([]); // 箱型
    const client = ref<SelectOption[]>([]); // 全部client
    const cntrOper = ref<SelectOption[]>([]); // 供应商
    const cntrCorp = ref<SelectOption[]>([]); // 客户
    const cntrOwner = ref<SelectOption[]>([]); // 成本中心

    const cntrStatus = ref<SelectOption[]>([]); // 箱状况
    const cntrDam = ref<SelectOption[]>([]); // 好坏
    const replyId = ref<SelectOption[]>([
        { value: 'S', label: '提交' },
        { value: 'R', label: '批复' },
        { value: 'E', label: '退回' },
    ]); // 修箱报价、批复
    const cyCfs = ref<SelectOption[]>([]); // 站点
    const cntrStat = ref<SelectOption[]>([]); // 箱动态
    const cntrGateInStat = ref<SelectOption[]>([]); // 进场箱动态
    const cntrGateOutStat = ref<SelectOption[]>([]); // 出场箱动态
    const contractKind = ref<SelectOption[]>([]); // 委托类型
    // const refMachine = ref<SelectOption[]>([]); // 冷机品牌
    // const place = ref<SelectOption[]>([]); // 地点
    const currency = ref<SelectOption[]>([]); // 货币
    const category = ref<SelectOption[]>([]); // 资金账号
    // const feetyp = ref<SelectOption[]>([]); // 费用类型
    const feecod = ref<SelectOption[]>([]); // 费目
    // const feetypcod = ref<CascaderOption[]>([]); // 级联费目
    // const transKind = ref<SelectOption[]>([]); // 运输方式
    // const payKind = ref<SelectOption[]>([]); // 付款方式
    async function initData() {
        const req = new Request('业务DW数据查询');
        const r = await req.post();
        cntrOper.value.length = 0;
        cntrCorp.value.length = 0;
        cntrOwner.value.length = 0;
        client.value.length = 0;
        r.obj['Client'].forEach((e: any) => {
            if (e.provid_id === 'Y') {
                cntrOper.value.push({
                    label: e.client_nam_c,
                    value: e.id,
                });
            }
            if (e.custom_id === 'Y') {
                cntrCorp.value.push({
                    label: e.client_nam_c,
                    value: e.id,
                });
            }
            if (e.cntr_owner_id === 'Y') {
                cntrOwner.value.push({
                    label: e.client_nam_c,
                    value: e.id,
                });
            }
            client.value.push({
                label: e.client_nam_c,
                value: e.id,
            });
        });

        cntrSiz.value = r.obj['CntrSiz'];
        cntrTyp.value = r.obj['CntrTyp'];
        // cntrOper.value = r.obj['CntrOper'];
        // cntrCorp.value = r.obj['CntrCorp'];
        // cntrOwner.value = r.obj['CntrOwner'];
        cntrDam.value = r.obj['CntrDam'];
        cyCfs.value = r.obj['Cfs'];
        client.value = client.value.concat(cyCfs.value);
        cntrStat.value.length = 0;
        cntrGateInStat.value.length = 0;
        cntrGateOutStat.value.length = 0;
        r.obj['CntrStat'].forEach((e: any) => {
            cntrStat.value.push({
                label: e.stat_nam,
                value: e.stat_cod,
            });
            if (e.carry_id === 'A') {
                cntrGateInStat.value.push({
                    label: e.stat_nam,
                    value: e.stat_cod,
                });
            }
            if (e.carry_id === 'T') {
                cntrGateOutStat.value.push({
                    label: e.stat_nam,
                    value: e.stat_cod,
                });
            }
        });
        contractKind.value = r.obj['ContractKind'];
        // place.value = r.obj['Place'];
        cntrStatus.value = r.obj['CntrStatus'];
        currency.value = r.obj['Currency'];
        category.value = r.obj['Category'];
        // feetyp.value = r.obj['FeeTyp'];
        feecod.value = r.obj['FeeCod'];
        // feetypcod.value = r.obj['FeeTypCod'];
        // transKind.value = r.obj['TransKind'];
        // payKind.value = r.obj['PayKind'];
        // refMachine.value = r.obj['RefMachine'];
    }
    return {
        SelectOptionCarry,
        SelectOptionEF,
        SelectOptionYN,
        // SelectOptionPlanKind,
        SelectOptionFeeInOut,
        SelectOptionTrade,
        SelectOptionReply,
        SelectOptionCntrOwnerReply,
        cntrSiz,
        cntrTyp,
        cntrOper,
        cntrCorp,
        cntrOwner,
        cntrDam,
        cyCfs,
        cntrStat,
        cntrGateInStat,
        cntrGateOutStat,
        // refMachine,
        // place,
        cntrStatus,
        contractKind,
        currency,
        client,
        category,
        // feetyp,
        feecod,
        // feetypcod,
        // transKind,
        // payKind,
        initData,
        replyId,
    };
});
